<template>
  <div class="list-table">
    <div v-if="this.$route.query.dealType !== 'bf'" class="mb20">
      <el-switch
        v-model="cashflowQuarterOrMonth"
        :active-text="$t('按月统计')"
        :inactive-text="$t('按季统计')"
        @change="onChange"
      />
      <div style="height: 400px;width: 100%">
        <barLineChart v-if="optionData.datas.length > 0" height="100%" :chart-data="optionData" />
        <div v-else class="noneData">
          <div>
            <svg-icon icon-class="none" class-name="none-icon" />
            <p>{{ $t('暂无数据') }}</p>
          </div>
        </div>
      </div>
      <el-row class="cashflow">
        <el-col :span="8">
          <div class="">IRR
            <el-tooltip placement="bottom">
              <div slot="content">
                {{ $t('根据现金流自动计算') }}<br>
              </div>
              <i class="el-icon-question" style="color: #595a5a;" />
            </el-tooltip>
          </div>
          <div v-if="dealCashflowVo" class=""><el-link type="primary" @click="findIRR">{{ (dealCashflowVo.irr !== 0 && dealCashflowVo.irr !== null ? dealCashflowVo.irr: $t('暂无数据')) }}</el-link></div>
        </el-col>
        <el-col :span="8">
          <div class="">MOIC
            <el-tooltip placement="bottom">
              <div slot="content">
                {{ $t('流入现金流 / 流出现金流') }}
              </div>
              <i class="el-icon-question" style="color: #595a5a;" />
            </el-tooltip>
          </div>
          <div v-if="dealCashflowVo" class="">{{ (dealCashflowVo.moic !== 0 && dealCashflowVo.moic !== null ? dealCashflowVo.moic: $t('暂无数据')) }}</div>
        </el-col>
      </el-row>
    </div>
    <div v-if="this.$route.query.dealType === 'bf'" class="area-header">
      <span class="area-header-title">{{ $t('指标汇总') }}</span>
    </div>
    <div v-if="this.$route.query.dealType === 'bf'" v-loading="tableLoading" class="mb20">
      <el-row id="table" class="table" :gutter="10">
        <el-col v-for="(statistical,index) in dataList" :key="index" style="margin-top: 10px;" :span="6">
          <div v-for="(value,key) in statistical" :key="key" :class="['fund-parent', key === 'IRR' ? 'btnIrr' : '']" @click="key === 'IRR' ? findIRR() : null">
            <div class="left-text">
              <circle-chart :expense="[expenseSum, value]" width="18px" style="min-width: 18px;" />
              <el-tooltip class="item" effect="dark" :content="selectDictLabel(operteTypeOptions,key)" placement="bottom">
                <div class="label">{{ key === 'SUM' ? '合计' : selectDictLabel(operteTypeOptions,key) }}</div>
              </el-tooltip>
            </div>
            <div class="money" :style="{ 'color': key === 'IRR' ? '#1890ff' : '#333436', 'font-weight': key === 'IRR' ? 'none' : 'bold' }">{{ moneyFormat(value, undefined, 2, true) }}</div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="area-header">
      <span class="area-header-title">{{ $t('项目现金流') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('现金流类型')" prop="type" label-width="120">
        <el-select v-model="queryParams.type" :placeholder="$t('现金流类型')" clearable>
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="isShowDealName" :label="$t('项目名称')" prop="dealId">
        <MainBodySelect
          v-model="queryParams.dealId"
          parameters="deal"
        />
      </el-form-item>
      <el-form-item :label="$t('承担主体')" prop="investorId">
        <el-select v-model="queryParams.investorId" value="" :placeholder="$t('承担主体')" clearable>
          <el-option
            v-for="investment in investmentList"
            :key="investment.id"
            :label="investment.investorName"
            :value="investment.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('发生时间')" prop="operateDates">
        <DatePicker v-model="operateDates" type="daterange" />
      </el-form-item>
      <el-form-item :label="$t('方向')" prop="direction">
        <el-select v-model="queryParams.direction" :placeholder="$t('方向')" clearable>
          <el-option
            v-for="dict in directionOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('业务类型')" prop="operateType">
        <el-select v-model="queryParams.operateType" :placeholder="$t('业务类型')" clearable>
          <el-option
            v-for="dict in operateTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:cashflow:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:cashflow:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:cashflow:edit']"
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >{{ $t('导入') }}
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['deal:cashflow:view']"-->
      <!--          type="primary"-->
      <!--          icon="el-icon-info"-->
      <!--          size="mini"-->
      <!--          @click="getIrr"-->
      <!--        >{{ $t("获取IRR") }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealCashflowList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column v-if="isShowDealName" :label="$t('项目名称')" align="center" prop="dealBase.dealName" min-width="150" />
      <el-table-column :label="$t('承担主体')" align="center" prop="investorName" min-width="150">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.investorName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('现金流类型')" align="center" prop="type" :formatter="typeFormat" show-overflow-tooltip min-width="100" />
      <el-table-column :label="$t('业务类型')" align="center" prop="operateType" :formatter="operateTypeFormat" show-overflow-tooltip min-width="90" />
      <el-table-column :label="$t('权益变更时间')" align="center" prop="equityChangeTime" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.equityChangeTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('发生时间')" align="center" prop="operateDate" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operateDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目币种')" align="center" prop="currency" :formatter="currencyFormat" show-overflow-tooltip min-width="70" />
      <el-table-column :label="$t('发生金额') + $t('(元)')" align="center" prop="operateAmount" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span style="text-align: right" class="money-text">{{ moneyFormat(dealMoneyFormat(scope.row), undefined, 2, true) }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="showCurrencyField" :label="$t('主体币种')" align="center" prop="currencyRate" :formatter="currencyFormatRate" show-overflow-tooltip min-width="70" />
      <el-table-column v-if="showCurrencyField" :label="$t('发生金额') + $t('(元)')" align="center" prop="operateAmountRMB" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span style="text-align: right" class="money-text">{{ moneyFormat(dealMoneyFormatRMB(scope.row), undefined, 2, true) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column :label="$t('方向')" align="center" prop="direction" :formatter="directionFormat" show-overflow-tooltip min-width="50" /> -->
      <!-- <el-table-column :label="$t('参与IRR计算')" align="center" prop="whetherIrr" :formatter="whetherIrrFormat" show-overflow-tooltip min-width="100" /> -->
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="150">
        <template slot="header">
          <span>{{ $t('操作') }}</span>
          <!--          <el-tooltip placement="top">-->
          <!--            <div slot="content">-->
          <!--              {{ $t('不是从现金流功能添加的数据，不能修改与删除，如需修改请修改来源数据') }}-->
          <!--            </div>-->
          <!--            <i class="el-icon-question" />-->
          <!--          </el-tooltip>-->
        </template>
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:cashflow:edit']"
            size="small"
            type="text"
            :icon=" 'el-icon-edit'"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['deal:cashflow:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"

            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目现金流对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealCashflowForm ref="dealCashflowForm" />
    </el-dialog>

    <!-- 现金流IRR对话框 -->
    <el-dialog :title="$t('IRR')" :visible.sync="irrOpen" custom-class="customDialog" :close-on-click-modal="false" width="551px" :lock-scroll="false" append-to-body>
      <el-table v-loading="irrLoading" :data="dealIrrList" border class="nowrapTable formTable">
        <el-table-column :label="$t('序号')" align="center" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('维度')" align="center" prop="dimension" width="259" />
        <el-table-column :label="$t('IRR')" align="center" prop="xirr" width="200">
          <template slot-scope="scope">
            <span><el-link type="primary" @click="findXIrrDetails(scope.row)">{{ moneyFormat(scope.row.xirr, undefined, 2, true) }}</el-link></span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div slot="tip" class="el-upload__tip" style="color:red">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="info" class="el-icon-download el-icon--right" style="font-size:12px;float:left;" @click="fetchTemplate">
          {{ $t('下载模板') }}
        </el-button>
        <el-button @click="upload.open = false">{{ $t("取消") }}</el-button>
        <el-button type="primary" @click="submitFileForm">{{ $t("确定") }}</el-button>
      </div>
    </el-dialog>

    <!-- xIrr计算明细对话框 -->
    <el-dialog :title="$t('计算明细')" :visible.sync="xIrrDetailsOpen" :close-on-click-modal="false" :lock-scroll="false" :width="'50%'" custom-class="customDialog" append-to-body>
      <xIrrBaseDetailsList ref="xIrrBaseDetailsList" class="dialog-content" />
      <div slot="footer" class="dialog-footer mt-15" style="text-align: right;">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportXIrrHandle"
        >{{ $t('导出') }}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listDealCashflow,
  delDealCashflow,
  getDealCashflowIrr,
  getDealCashFlowPageThreeValue,
  getDealCashFlowIrrHistory,
  getChart, getDicts
} from '@/api/deal/cashflow/dealCashflow'
import dealCashflowForm from './dealCashflowForm.vue'
import { getDealInvestmentIrrHistory, listDealInvestment } from '@/api/deal/investment/dealInvestment'
import MainBodySelect from '@/components/MainBodySelect'
import { getToken } from '@/utils/auth'
import CircleChart from '@/views/chart/circleChart'
import xIrrBaseDetailsList from '@/components/Xirr/details/xirrBaseDetailsList'
import { cashFlowChartsDeal } from '@/api/deal/cashflow/dealCashflow'
import barLineChart from '@/views/chart/barLineChart.vue'
export default {
    components: {
        dealCashflowForm,
        MainBodySelect,
        barLineChart,
        CircleChart,
        xIrrBaseDetailsList
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          irrLoading: false,
          // 总条数
          total: 0,
          // 项目现金流表格数据
          dealCashflowList: [],
          // 是否展示项目名称
          isShowDealName: false,
          // 弹出层标题
          title: '现金流',
          // 是否显示弹出层
          formOpen: false,
          irrOpen: false,
          xIrrDetailsOpen: false,
          // 现金流类型  预计 实际字典
          typeOptions: [],
          // 方向：流入、流出字典
          directionOptions: [],
          // 类型：投资、回款、费用字典
          operateTypeOptions: [],
          // 币种字典
          currencyOptions: [],
          // 是否参与IRR计算字典
          whetherIrrOptions: [],
          // 当前项目投资主体
          investmentList: [],
          // 发生时间 参数
          operateDates: [],
          // 查询参数
          queryParams: {
              type: undefined,
              dealId: this.$route.query.id,
              dataId: undefined,
              component: undefined,
              investorId: undefined,
              startDate: undefined,
              endDate: undefined,
              direction: undefined,
              operateType: undefined,
              whetherIrr: 'Y',
              pageNum: 1,
              pageSize: 10
          },
        // 导入参数
        upload: {
          // 是否显示弹出层
          open: false,
          // 弹出层标题
          title: '',
          // 是否禁用上传
          isUploading: false,
          // 设置上传的请求头部
          headers: { Authorization: 'Bearer ' + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + '/cashflow/dealCashflow/importData'
        },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
        type: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], dealId: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], investorId: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], operateDate: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], operateAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], operateType: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ] },
        cashflowQuarterOrMonth: false,
        // 基金现金流合计信息
        dealCashflowVo: {},
        // 项目Irr记录集合
        dealIrrList: [],
        showCurrencyField: false,
        tableLoading: true,
        dataList: [],
        expenseSum: 0,
        operteTypeOptions: [],
        optionData: {
          datas: []
        }
      }
  },
  computed: {

  },
  watch: {
    'queryParams.dealId': {
      handler(val) {
        this.investmentList = undefined
        this.queryParams.investorId = undefined
        listDealInvestment({ 'dealId': val }).then(response => {
          this.investmentList = response.rows
        })
      },
      immediate: true // 页面打开时就执行
    }
  },
  created() {
      this.getList()
      if (this.$route.query.id) {
        getDicts().then(res => {
          this.operteTypeOptions = res.data
          this.getLists()
        })
      }
      this.getCashFlowCombined()
      this.getDicts('cash_flow_type').then(response => {
          this.typeOptions = response.data
      })
      this.getDicts('cash_flow_direction').then(response => {
          this.directionOptions = response.data
      })
      this.getDicts('deal_cash_flow_type' + (this.$route.query.dealType === 'spo' ? '_spo' : '')).then(response => {
          this.operateTypeOptions = response.data
      })
      this.getDicts('currency').then(response => {
        this.currencyOptions = response.data
      })
      this.getDicts('sys_yes_no').then(response => {
          this.whetherIrrOptions = response.data
      })
      /* listDealInvestment({ 'dealId': this.$route.query.id }).then(response => {
        this.investmentList = response.rows
      }) */
      // 根据项目ID是否为空 来显示项目名称
      this.isShowDealName = this.$route.query.id == null || this.$route.query.id === undefined
  },
  mounted() {},
  methods: {
    disbtn(val) {
      if (val) {
        return true
      } else {
        return false
      }
    },
    /** 查询项目现金流列表 */
    getList() {
        this.loading = true
        if (this.operateDates != null && this.operateDates.length > 1) {
          this.queryParams.startDate = this.operateDates[0]
          this.queryParams.endDate = this.operateDates[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        if (this.$route.query.id) {
          this.getLists()
          this.getCashFlowCombined()
        }
        listDealCashflow(this.addDateRange(this.queryParams, this.operateDates)).then(response => {
            this.dealCashflowList = response.rows
            this.total = response.total
            // 格式化页面list, 如果所有币种都相同, 展示一列就行
            this.showCurrency()
            this.loading = false
        })
        this.onChange()
    },
    onChange() {
      var params = {
        dealId: this.$route.query.id,
        quarterOrMonth: this.cashflowQuarterOrMonth
      }
      this.optionData = {
        legend: true,
        datas: [],
        yAxis2: false,
        yAxisName2: ' ',
        valueFormatter: true,
        legendLeft: 'center',
        color: ['#5F69E4', '#14C8C7'],
        xLabel: []
      }
      cashFlowChartsDeal(params).then(response => {
        if (response.data != null) {
          this.optionData.xLabel = response.data.dateList
          this.optionData.datas = [
            {
              name: this.$t('正现金流'),
              type: 'bar',
              stack: '1',
              data: response.data.positiveCashFlowList
            },
            {
              name: this.$t('负现金流'),
              type: 'bar',
              stack: '1',
              data: response.data.negativeCashFlowList.map(v => { return v * -1 })
            }
          ]
        }
      })
    },
    //  格式化页面list, 如果所有币种都相同, 展示一列就行
    showCurrency() {
      this.showCurrencyField = false
      this.dealCashflowList && this.dealCashflowList.forEach(item => {
        if (item.currencyRate !== item.currency && !this.showCurrencyField) {
          this.showCurrencyField = true
        }
      })
    },
    // 查询基金现金流合计
    getCashFlowCombined() {
      if (this.$route.query.id !== undefined) {
        getDealCashFlowPageThreeValue({ dealId: this.$route.query.id, investorId: this.queryParams.investorId }).then(response => {
          this.dealCashflowVo = response.data
        })
      }
    },
    // 现金流类型  预计 实际字典翻译
    typeFormat(row) {
      return this.selectDictLabel(this.typeOptions, row.type)
    },
    // 币种字典翻译
    currencyFormat(row) {
      return this.selectDictLabel(this.currencyOptions, row.currency)
    },
    currencyFormatRate(row) {
      if (row.operateAmountRMB !== undefined && row.operateAmountRMB !== null && row.operateAmountRMB !== '') {
        return this.selectDictLabel(this.currencyOptions, row.currencyRate)
      } else {
        return ''
      }
    },
    // 方向：流入、流出字典翻译
    directionFormat(row) {
      return this.selectDictLabel(this.directionOptions, row.direction)
    },
    // 类型：投资、回款、费用字典翻译
    operateTypeFormat(row) {
      return this.selectDictLabel(this.operateTypeOptions, row.operateType)
    },
    // 是否参与IRR计算字典翻译
    whetherIrrFormat(row) {
      return this.selectDictLabel(this.whetherIrrOptions, row.whetherIrr)
    },
    dealMoneyFormat(row) {
      if (row.direction === 'LC') {
        return 0 - row.operateAmount
      }
      return row.operateAmount
    },
    dealMoneyFormatRMB(row) {
      if (row.direction === 'LC') {
        return 0 - row.operateAmountRMB
      }
      return row.operateAmountRMB
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            type: undefined,
            dealId: undefined,
            dataId: undefined,
            component: undefined,
            investorId: undefined,
            operateDate: undefined,
            equityChangeTime: undefined,
            operateAmount: undefined,
            direction: '0',
            operateType: undefined,
            whetherIrr: '0',
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.operateDates = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealCashflowForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealCashflowForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealCashflow(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        this.downLoadExcelPost('/cashflow/dealCashflow/export', this.addDateRange(this.queryParams, this.operateDates))
    },
    // 计算irr
    getIrr() {
      getDealCashflowIrr(this.queryParams).then(res => {
        let msg = ''
        if (res.data === 502) {
          msg = this.$t('计算失败：小于或等于一条现金流')
        } else if (res.data === 503) {
          msg = this.$t('计算失败：第一条现金流的时间不是最早时间')
        } else if (res.data === 504) {
          msg = this.$t('计算失败：第一条现金流的payment的值不为负')
        } else {
          msg = res.data
        }
        this.$alert(msg, '当前数据IRR(%)', {
          dangerouslyUseHTMLString: true
        })
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = this.$t('项目现金流导入')
      this.upload.open = true
    },
    // 文件上传中处理
    handleFileUploadProgress() {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert(response.msg, this.$t('导入结果'), { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 下载模板
    fetchTemplate() {
      var href1 = window.location.href
      var href2 = this.$route.path
      var url = href1.substring(0, href1.indexOf(href2))
      window.location.href = url + '/template/projectCashflowImportTemplate.xlsx'
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    findIRR() {
      this.dealIrrList = []
      this.irrOpen = true
      this.irrLoading = true
      if (this.$route.query.id !== undefined) {
        const getIrrHistory = this.queryParams.investorId ? getDealInvestmentIrrHistory : getDealCashFlowIrrHistory
        getIrrHistory(this.queryParams.investorId ? { id: this.queryParams.investorId } : this.$route.query.id).then(response => {
          this.dealIrrList = response.rows
        })
      }
      this.irrLoading = false
    },
    getLists() {
      this.tableLoading = true
      getChart({ dealId: this.$route.query.id, investmentId: this.queryParams.investorId }).then(res => {
        const arr = []
        const hasArr = []
        // var sum = 0
        res.data.data.forEach(item => {
          const obj = {}
          obj[item.operateType] = item.operateAmount
          arr.push(obj)
          hasArr.push(item.operateType)
          // sum += item.operateAmount
        })
        this.operteTypeOptions.forEach(dict => {
          if (!hasArr.includes(dict.dictValue)) {
            const obj = {}
            obj[dict.dictValue] = ''
            arr.push(obj)
          }
        })
        this.dataList = arr
        console.log(this.dataList)
        this.tableLoading = false
      })
    },
    findXIrrDetails(row) {
      this.xIrrDetailsOpen = true
      this.$nextTick(() => {
        this.$refs.xIrrBaseDetailsList.init(row.id)
      })
    },
    exportXIrrHandle() {
      this.$nextTick(() => {
        this.$refs.xIrrBaseDetailsList.exportHandle()
      })
    },
    isRatio(type) {
      if (type === 'IRR' || type === 'DPI' || type === 'MOIC') {
        return '(%)'
      }
      return ''
    }
  }
}
</script>
<style lang="scss" scoped>
.table {
  .fund-parent {
    background-color: #F8F9FA;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    overflow: hidden;
    padding: 10px 10px 10px 5px;
  }
  .left-text{
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
    min-width: 30%;
    .label{
      font-size: 13px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }
  }
  .money{
    font-size: 13px;
  }
  .wrap-pop-expense {
    /* 背景色 */
    background: rgba(0,0,0,.7) !important;
    color: #fff !important;
    border: 1px solid rgba(0,0,0,.7) !important;
  }

  /* 下方是去除三角箭头的代码 */
  .wrap-pop-expense[x-placement^="bottom"] .popper__arrow::after {
    border-bottom-color: rgba(0,0,0,.7) !important;
  }

  .wrap-pop-expense[x-placement^="bottom"] .popper__arrow {
    border-bottom-color: rgba(0,0,0,.7) !important;
  }
}

/deep/.customDialog .el-dialog__body {
  height: 48vh;
  overflow-y: auto;
  .list-table {
    margin: -20px;
  }
}
.btnIrr{
  color: #1890ff;
  cursor: pointer;
}

</style>
